package com.wlyuan.open.domain.source.assembler;

import com.wlyuan.core.domain.MappingIds;
import com.wlyuan.core.marker.NamedStatus;
import com.wlyuan.open.dto.tenant.OpenCompanyTenantSyncDTO;
import com.wlyuan.open.dto.tenant.OpenDriverTenantSyncDTO;
import com.wlyuan.tenant.dto.company.CompanyTenantRewriteDTO;
import com.wlyuan.tenant.dto.driver.DriverTenantRewriteDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

/**
 * @author lijing
 */
public class TenantAssembler {

    private static final Assembler ASSEMBLER = Mappers.getMapper(Assembler.class);

    @Mapper(uses = {
            MappingIds.class,
    }, imports = {
            NamedStatus.class,
    })
    public interface Assembler {

        @Mappings({
                @Mapping(source = "sourceKey", target = "tenantId"),

                @Mapping(source = "tenantConfig", target = "limitTimeSet"),
                @Mapping(source = "sourceKey", target = "limitTimeSet.tenantId"),
                @Mapping(constant = "0L", target = "limitTimeSet.userId"),
        })
        CompanyTenantRewriteDTO assemble(OpenCompanyTenantSyncDTO source);


        @Mappings({
                @Mapping(source = "sourceKey", target = "tenantId"),
                @Mapping(target = "appId", source = "wxAppId")
        })
        DriverTenantRewriteDTO assemble(OpenDriverTenantSyncDTO source);
    }

    public static CompanyTenantRewriteDTO assemble(OpenCompanyTenantSyncDTO source) {
        return ASSEMBLER.assemble(source);
    }

    public static DriverTenantRewriteDTO assemble(OpenDriverTenantSyncDTO source) {
        return ASSEMBLER.assemble(source);
    }
}
